﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Hosting;

/// <summary>
/// Summary description for CustomAdminControlVirtualProvider
/// </summary>
public class CustomAdminControlVirtualProvider : VirtualPathProvider
{
    private bool IsAppResourcePath(string virtualPath) 
    { 
        String checkPath = VirtualPathUtility.ToAppRelative(virtualPath);
        return checkPath.StartsWith("~/CustomAdminPage/", StringComparison.InvariantCultureIgnoreCase); 
    }

    public override bool FileExists(string virtualPath)
    {
        return (IsAppResourcePath(virtualPath) || base.FileExists(virtualPath));
    }

    public override VirtualFile GetFile(string virtualPath) 
    { 
        if (IsAppResourcePath(virtualPath))
            return new CustomAdminControlVirtualFile(virtualPath);
        else 
            return base.GetFile(virtualPath);
    }

    public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart) 
    { 
        if (IsAppResourcePath(virtualPath)) 
            return null; 
        else 
            return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart); 
    } 
}
